home *** CD-ROM | disk | FTP | other *** search
/ ftp.mactech.com 2010 / ftp.mactech.com.tar / ftp.mactech.com / machack / Hacks97 / WarriorsProgress.sit / Warrior’s Progress / source code / Source / Libraries / Views / Standard Views / StringView.cp < prev    next >
Text File  |  1997-06-28  |  3KB  |  141 lines

  1. // StringView.cp
  2.  
  3. #ifndef StringView_h
  4. #include "StringView.h"
  5. #endif
  6. #ifndef ViewMap_h
  7. #include "ViewMap.h"
  8. #endif
  9. #ifndef Justification_h
  10. #include "Justification.h"
  11. #endif
  12. #ifndef ForegroundColorMaintainer_h
  13. #include "ForegroundColorMaintainer.h"
  14. #endif
  15. #ifndef BackgroundColorMaintainer_h
  16. #include "BackgroundColorMaintainer.h"
  17. #endif
  18. #ifndef FaceMaintainer_h
  19. #include "FaceMaintainer.h"
  20. #endif
  21. #ifndef TextModeMaintainer_h
  22. #include "TextModeMaintainer.h"
  23. #endif
  24. #ifndef IntegerFaceMetrics_h
  25. #include "IntegerFaceMetrics.h"
  26. #endif
  27. #ifndef TemporaryPort_h
  28. #include "TemporaryPort.h"
  29. #endif
  30.  
  31. StringView::StringView( ::Face face )
  32.   : HasFace( face ),
  33.      HasVerticalJustification( Justification::Center() ),
  34.      HasHorizontalJustification( Justification::Leading() )
  35.   {
  36.   }
  37.  
  38. void StringView::Draw( const ViewMap& map ) const
  39.   {
  40.     ForegroundColorMaintainer foreground( ForegroundColor() );
  41.     BackgroundColorMaintainer background( BackgroundColor() );
  42.     FaceMaintainer face( Face() );
  43.     TextModeMaintainer mode( SourceMode::srcCopy );
  44.     
  45.     Rectangle exterior( map.Bounds() );
  46.     Rectangle interior( exterior );
  47.     
  48.     IntegerFaceMetrics metrics( IntegerFaceMetrics::Current() );
  49.     
  50.     uint32 width = StringWidth( string );
  51.     HorizontalJustification().InsetWidth( interior, width );
  52.     VerticalJustification().InsetHeight( interior, metrics.UnleadedHeight() );
  53.     
  54.     if ( string.Length() > 0 )
  55.       {
  56.         MoveTo( interior.left, interior.bottom - metrics.Descent() );
  57.         DrawJustified( reinterpret_cast<int8 *>( const_cast<uint8*>( &string[0] ) ),
  58.                             string.Length(),
  59.                             Fixed(interior.Width() - width ) << 16,
  60.                             smOnlyStyleRun,
  61.                             PointObject(1,1), PointObject(1,1) );
  62.       }
  63.     
  64.     Rectangle right( exterior );
  65.     right.left = map.Port().PenPosition().h;
  66.     EraseRect( &right );
  67.     
  68.     Rectangle top( exterior );
  69.     top.bottom = interior.top;
  70.     EraseRect( &top );
  71.     
  72.     Rectangle bottom( exterior );
  73.     bottom.top = interior.bottom;
  74.     EraseRect( &bottom );
  75.     
  76.     Rectangle left( exterior );
  77.     left.right = interior.left;
  78.     EraseRect( &left );
  79.   }
  80.  
  81. void StringView::SetString( ConstPString newString )
  82.   {
  83.     if ( string == newString )
  84.         return;
  85.     
  86.     string = newString;
  87.     Invalidate();
  88.   }
  89.  
  90. void StringView::ForegroundColorChanged()
  91.   {
  92.     Invalidate();
  93.   }
  94.  
  95. void StringView::BackgroundColorChanged()
  96.   {
  97.     Invalidate();
  98.   }
  99.  
  100. void StringView::FaceChanged()
  101.   {
  102.     Invalidate();
  103.   }
  104.  
  105. void StringView::VerticalJustificationChanged()
  106.   {
  107.     Invalidate();
  108.   }
  109.  
  110. void StringView::HorizontalJustificationChanged()
  111.   {
  112.     Invalidate();
  113.   }
  114.  
  115. uint16 StringView::MinimumHeight() const
  116.   {
  117.     return IntegerFaceMetrics( Face() ).UnleadedHeight();
  118.   }
  119.  
  120. uint16 StringView::ReasonableWidth() const
  121.   {
  122.     return 48;
  123.   }
  124.  
  125. uint16 StringView::BestWidth() const
  126.   {
  127.     return WidthOf( string );
  128.   }
  129.  
  130. uint16 StringView::BestHeight() const
  131.   {
  132.     return MinimumHeight();
  133.   }
  134.  
  135. uint16 StringView::WidthOf( ConstPString s ) const
  136.   {
  137.     TemporaryPort port;
  138.     port.Port().SetFace( Face() );
  139.     return StringWidth( s );
  140.   }
  141.